package com.fanrui.code.util;

import java.util.Date;

import com.fanrui.code.entity.PlayerLog;
import com.fanrui.code.player.Player;
import com.fanrui.code.util.PlayerLogUtil.PlayerOpertionType;

public class PlayerLogBuilder {

	private Long userId;

	private Date createTime;

	private Integer operationType;

	private Integer operationIntValue1;

	private Integer operationIntValue2;

	private Integer operationIntValue3;

	private Long operationLongValue1;

	private Long operationLongValue2;

	private String operationStrValue1;
	
	private String operationStrValue5;

	private String operationStrValue2;

	private Long operationBeforeGold;

	private Long operationAfterGold;

	private Long operationBeforeMoney;

	private Long operationAfterMoney;

	private String operationBeforeItem;

	private String operationAfterItem;

	public PlayerLogBuilder() {
		createTime = new Date();
	}

	public PlayerLogBuilder setUserId(Long userId) {
		this.userId = userId;
		return this;
	}

	public PlayerLogBuilder setCreateTime(Date createTime) {
		this.createTime = createTime;
		return this;
	}

	public PlayerLogBuilder setOperationType(PlayerOpertionType operationType) {
		this.operationType = operationType.getValue();
		return this;
	}

	public PlayerLogBuilder setOperationIntValue1(Integer operationIntValue1) {
		this.operationIntValue1 = operationIntValue1;
		return this;
	}

	public PlayerLogBuilder setOperationIntValue2(Integer operationIntValue2) {
		this.operationIntValue2 = operationIntValue2;
		return this;
	}

	public PlayerLogBuilder setOperationIntValue3(Integer operationIntValue3) {
		this.operationIntValue3 = operationIntValue3;
		return this;
	}

	public PlayerLogBuilder setOperationLongValue1(Long operationLongValue1) {
		this.operationLongValue1 = operationLongValue1;
		return this;
	}

	public PlayerLogBuilder setOperationLongValue2(Long operationLongValue2) {
		this.operationLongValue2 = operationLongValue2;
		return this;
	}
	public PlayerLogBuilder setOperationStrValue5(String operationStrValue5) {
		this.operationStrValue5 = operationStrValue5;
		return this;
	}

	public PlayerLogBuilder setOperationStrValue1(String operationStrValue1) {
		this.operationStrValue1 = operationStrValue1;
		return this;
	}

	public PlayerLogBuilder setOperationStrValue2(String operationStrValue2) {
		this.operationStrValue2 = operationStrValue2;
		return this;
	}
	
	/**
	 * 设置玩家操作之后的数据
	 * @param data
	 * @return
	 */
	public PlayerLogBuilder setAfterPlayerData(Player player) {
		this.userId = player.getId();
		this.operationAfterGold = player.getGold();
		this.operationAfterMoney = player.getMoney();
		return this;
	}
	
	/**
	 * 设置玩家操作之前的数据
	 * @param data
	 * @return
	 */
	public PlayerLogBuilder setBeforePlayerData(PlayerData data) {
		this.operationBeforeGold = data.getGold();
		this.operationBeforeMoney = data.getMoney();
		return this;
	}

	public PlayerLogBuilder setPlayer(Player player) {
		this.userId = player.getId();
		this.operationAfterGold = player.getGold();
		this.operationAfterMoney = player.getMoney();
		return this;
	}
	
	public PlayerLogBuilder setPlayerData(PlayerData data) {
		this.operationBeforeGold = data.getGold();
		this.operationBeforeMoney= data.getMoney();
		return this;
	}
	
	public PlayerLog buildLog() {
		PlayerLog log = new PlayerLog();
		log.setUserId(userId);
		log.setCreateTime(createTime);
		log.setOperationType(operationType);
		log.setOperationIntValue1(operationIntValue1);
		log.setOperationIntValue2(operationIntValue2);
		log.setOperationIntValue3(operationIntValue3);
		log.setOperationLongValue1(operationLongValue1);
		log.setOperationLongValue2(operationLongValue2);
		log.setOperationStrValue1(operationStrValue1);
		log.setOperationStrValue2(operationStrValue2);
		log.setOperationBeforeGold(operationBeforeGold);
		log.setOperationAfterGold(operationAfterGold);
		log.setOperationStrValue5(operationStrValue5);
		log.setOperationBeforeMoney(operationBeforeMoney);
		log.setOperationAfterMoney(operationAfterMoney);
		log.setOperationBeforeItem(operationBeforeItem);
		log.setOperationAfterItem(operationAfterItem);
		return log;
	}

	public static PlayerLogBuilder createBuilder() {
		return new PlayerLogBuilder();
	}

}
